VtAddInput


Add a callback on file activity (read, write or error)

Syntax

VtAddInput fileID cmd

Description

Register a command or procedure callback that is called when an I/O stream is ready for file activity. When the stream referenced by fileID becomes readable, writable or generates an error, the callback command cmd is called with fileID as its argument. You can then read and write to the stream without fear of the interpreter blocking.

Notes

You must execute VtMainLoop to allow the callback to be called.

Example

The following code fragment illustrates the use of VtAddInput to filter the output of a UNIX system command, in this case find.

proc dumpFoundCB {fid} {
   
    set count 1
    while { $count > 0 } {
        set count [gets $fid line]  ;# read a line of input
        puts stdout ">> $line"
    }
        
     if { $count == -1 } { ;# end of file
        echo "\n\nFinished"
        exit 0
     }

}
   
   
set cmd {| /bin/find /usr -name "*" -print}
   
# open the pipe 
if [catch {set f [open $cmd ] } msg ] {
    echo "open failed"
    exit 1
}
   
#setup read handler on it..
VtAddInput $f dumpFoundCB
       
VtMainLoop